<?php

namespace app\backstage\model;

use think\Db;
use think\Model;

class PowerNode extends Model
{
    protected $table = 'cms_power_node';

    /*
     * 角色绑定
     */
    public function roles()
    {
        return $this->belongsToMany(ManagerRole::class, RoleToNodeAccess::class, 'role_id', 'node_id');
    }

    /*
     * 上级节点
     */
    public function parentNode()
    {
        return $this->hasOne(PowerNode::class, 'id', 'parent_node_id')->field("id,title");
    }

    public function getTypeAttr($value)
    {
        $status = [1 => '节点', 2 => '菜单'];
        return $status[$value];
    }

    public function getStatusAttr($value)
    {
        $status = [1 => '正常', 2 => '禁用'];
        return $status[$value];
    }
}